home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / ActView / ActiveViewer.jar / com / simeda / ActiveViewer / rfbProto.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-12-12  |  7.7 KB  |  294 lines

  1. package com.simeda.ActiveViewer;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import javax.microedition.io.Connector;
  7. import javax.microedition.io.StreamConnection;
  8.  
  9. class rfbProto {
  10.    static final String versionMsg = "RFB 003.003\n";
  11.    static final int ConnFailed = 0;
  12.    static final int NoAuth = 1;
  13.    static final int VncAuth = 2;
  14.    static final int VncAuthOK = 0;
  15.    static final int VncAuthFailed = 1;
  16.    static final int VncAuthTooMany = 2;
  17.    static final int FramebufferUpdate = 0;
  18.    static final int SetColourMapEntries = 1;
  19.    static final int Bell = 2;
  20.    static final int ServerCutText = 3;
  21.    static final int SetPixelFormat = 0;
  22.    static final int FixColourMapEntries = 1;
  23.    static final int SetEncodings = 2;
  24.    static final int FramebufferUpdateRequest = 3;
  25.    static final int KeyEvent = 4;
  26.    static final int PointerEvent = 5;
  27.    static final int ClientCutText = 6;
  28.    static final int EncodingRaw = 0;
  29.    static final int EncodingCopyRect = 1;
  30.    static final int EncodingRRE = 2;
  31.    static final int EncodingCoRRE = 4;
  32.    static final int EncodingHextile = 5;
  33.    static final int HextileRaw = 1;
  34.    static final int HextileBackgroundSpecified = 2;
  35.    static final int HextileForegroundSpecified = 4;
  36.    static final int HextileAnySubrects = 8;
  37.    static final int HextileSubrectsColoured = 16;
  38.    StreamConnection conn;
  39.    String host;
  40.    int port;
  41.    // $FF: renamed from: is java.io.DataInputStream
  42.    DataInputStream field_0;
  43.    // $FF: renamed from: os java.io.OutputStream
  44.    OutputStream field_1;
  45.    boolean inNormalProtocol = false;
  46.    int serverMajor;
  47.    int serverMinor;
  48.    String desktopName;
  49.    int framebufferWidth;
  50.    int framebufferHeight;
  51.    int bitsPerPixel;
  52.    int depth;
  53.    boolean bigEndian;
  54.    boolean trueColour;
  55.    int redMax;
  56.    int greenMax;
  57.    int blueMax;
  58.    int redShift;
  59.    int greenShift;
  60.    int blueShift;
  61.    int updateNRects;
  62.    int updateRectX;
  63.    int updateRectY;
  64.    int updateRectW;
  65.    int updateRectH;
  66.    int updateRectEncoding;
  67.    int copyRectSrcX;
  68.    int copyRectSrcY;
  69.    byte[] eventBuf = new byte[72];
  70.    int eventBufLen;
  71.    int pointerMask = 0;
  72.  
  73.    rfbProto(String var1, int var2) throws IOException {
  74.       this.host = var1;
  75.       this.port = var2;
  76.       this.conn = (StreamConnection)Connector.open("socket://" + this.host + ":" + this.port);
  77.       this.field_0 = this.conn.openDataInputStream();
  78.       this.field_1 = this.conn.openDataOutputStream();
  79.    }
  80.  
  81.    void close() {
  82.       try {
  83.          this.conn.close();
  84.          this.field_0.close();
  85.          this.field_1.close();
  86.       } catch (Exception var2) {
  87.          ((Throwable)var2).printStackTrace();
  88.       }
  89.  
  90.    }
  91.  
  92.    void readVersionMsg() throws IOException {
  93.       byte[] var1 = new byte[12];
  94.       this.field_0.readFully(var1);
  95.       if (var1[0] == 82 && var1[1] == 70 && var1[2] == 66 && var1[3] == 32 && var1[4] >= 48 && var1[4] <= 57 && var1[5] >= 48 && var1[5] <= 57 && var1[6] >= 48 && var1[6] <= 57 && var1[7] == 46 && var1[8] >= 48 && var1[8] <= 57 && var1[9] >= 48 && var1[9] <= 57 && var1[10] >= 48 && var1[10] <= 57 && var1[11] == 10) {
  96.          this.serverMajor = (var1[4] - 48) * 100 + (var1[5] - 48) * 10 + (var1[6] - 48);
  97.          this.serverMinor = (var1[8] - 48) * 100 + (var1[9] - 48) * 10 + (var1[10] - 48);
  98.       } else {
  99.          throw new IOException("Host " + this.host + " port " + this.port + " is not an RFB server");
  100.       }
  101.    }
  102.  
  103.    void writeVersionMsg() throws IOException {
  104.       byte[] var1 = new byte[12];
  105.       byte[] var2 = "RFB 003.003\n".getBytes();
  106.       System.arraycopy(var2, 0, var1, 0, 12);
  107.       this.field_1.write(var1);
  108.    }
  109.  
  110.    int readAuthScheme() throws IOException {
  111.       int var1 = this.field_0.readInt();
  112.       switch (var1) {
  113.          case 0:
  114.             int var2 = this.field_0.readInt();
  115.             byte[] var3 = new byte[var2];
  116.             this.field_0.readFully(var3);
  117.             throw new IOException(new String(var3));
  118.          case 1:
  119.          case 2:
  120.             return var1;
  121.          default:
  122.             throw new IOException("Unknown authentication scheme from RFB server " + var1);
  123.       }
  124.    }
  125.  
  126.    void writeClientInit() throws IOException {
  127.       this.field_1.write(1);
  128.    }
  129.  
  130.    void readServerInit() throws IOException {
  131.       this.framebufferWidth = this.field_0.readUnsignedShort();
  132.       this.framebufferHeight = this.field_0.readUnsignedShort();
  133.       this.bitsPerPixel = this.field_0.readUnsignedByte();
  134.       this.depth = this.field_0.readUnsignedByte();
  135.       this.bigEndian = this.field_0.readUnsignedByte() != 0;
  136.       this.trueColour = this.field_0.readUnsignedByte() != 0;
  137.       this.redMax = this.field_0.readUnsignedShort();
  138.       this.greenMax = this.field_0.readUnsignedShort();
  139.       this.blueMax = this.field_0.readUnsignedShort();
  140.       this.redShift = this.field_0.readUnsignedByte();
  141.       this.greenShift = this.field_0.readUnsignedByte();
  142.       this.blueShift = this.field_0.readUnsignedByte();
  143.       byte[] var1 = new byte[3];
  144.       this.field_0.read(var1);
  145.       int var2 = this.field_0.readInt();
  146.       byte[] var3 = new byte[var2];
  147.       this.field_0.readFully(var3);
  148.       this.desktopName = new String(var3);
  149.       this.inNormalProtocol = true;
  150.    }
  151.  
  152.    int readServerMessageType() throws IOException {
  153.       return this.field_0.read();
  154.    }
  155.  
  156.    void readFramebufferUpdate() throws IOException {
  157.       this.field_0.readByte();
  158.       this.updateNRects = this.field_0.readUnsignedShort();
  159.    }
  160.  
  161.    void readFramebufferUpdateRectHdr() throws IOException {
  162.       this.updateRectX = this.field_0.readUnsignedShort();
  163.       this.updateRectY = this.field_0.readUnsignedShort();
  164.       this.updateRectW = this.field_0.readUnsignedShort();
  165.       this.updateRectH = this.field_0.readUnsignedShort();
  166.       this.updateRectEncoding = this.field_0.readInt();
  167.       if (this.updateRectX + this.updateRectW > this.framebufferWidth || this.updateRectY + this.updateRectH > this.framebufferHeight) {
  168.          throw new IOException("Framebuffer update rectangle too large: " + this.updateRectW + "x" + this.updateRectH + " at (" + this.updateRectX + "," + this.updateRectY + ") (FW: " + this.framebufferWidth + ", FH: " + this.framebufferHeight + ")");
  169.       }
  170.    }
  171.  
  172.    void readCopyRect() throws IOException {
  173.       this.copyRectSrcX = this.field_0.readUnsignedShort();
  174.       this.copyRectSrcY = this.field_0.readUnsignedShort();
  175.    }
  176.  
  177.    String readServerCutText() throws IOException {
  178.       byte[] var1 = new byte[3];
  179.       this.field_0.read(var1);
  180.       int var2 = this.field_0.readInt();
  181.       byte[] var3 = new byte[var2];
  182.       this.field_0.readFully(var3);
  183.       return new String(var3);
  184.    }
  185.  
  186.    void writeFramebufferUpdateRequest(int var1, int var2, int var3, int var4, boolean var5) throws IOException {
  187.       System.out.println("Requesting update for x=" + var1 + " y=" + var2 + " w=" + var3 + " h=" + var4 + " incremental=" + var5);
  188.       byte[] var6 = new byte[]{3, (byte)(var5 ? 1 : 0), (byte)(var1 >> 8 & 255), (byte)(var1 & 255), (byte)(var2 >> 8 & 255), (byte)(var2 & 255), (byte)(var3 >> 8 & 255), (byte)(var3 & 255), (byte)(var4 >> 8 & 255), (byte)(var4 & 255)};
  189.       this.field_1.write(var6);
  190.    }
  191.  
  192.    void writeSetPixelFormat(int var1, int var2, boolean var3, boolean var4, int var5, int var6, int var7, int var8, int var9, int var10) throws IOException {
  193.       byte[] var11 = new byte[]{0, 0, 0, 0, (byte)var1, (byte)var2, (byte)(var3 ? 1 : 0), (byte)(var4 ? 1 : 0), (byte)(var5 >> 8 & 255), (byte)(var5 & 255), (byte)(var6 >> 8 & 255), (byte)(var6 & 255), (byte)(var7 >> 8 & 255), (byte)(var7 & 255), (byte)var8, (byte)var9, (byte)var10, 0, 0, 0};
  194.       this.field_1.write(var11);
  195.    }
  196.  
  197.    void writeFixColourMapEntries(int var1, int var2, int[] var3, int[] var4, int[] var5) throws IOException {
  198.       byte[] var6 = new byte[6 + var2 * 6];
  199.       var6[0] = 1;
  200.       var6[2] = (byte)(var1 >> 8 & 255);
  201.       var6[3] = (byte)(var1 & 255);
  202.       var6[4] = (byte)(var2 >> 8 & 255);
  203.       var6[5] = (byte)(var2 & 255);
  204.  
  205.       for(int var7 = 0; var7 < var2; ++var7) {
  206.          var6[6 + var7 * 6] = (byte)(var3[var7] >> 8 & 255);
  207.          var6[6 + var7 * 6 + 1] = (byte)(var3[var7] & 255);
  208.          var6[6 + var7 * 6 + 2] = (byte)(var4[var7] >> 8 & 255);
  209.          var6[6 + var7 * 6 + 3] = (byte)(var4[var7] & 255);
  210.          var6[6 + var7 * 6 + 4] = (byte)(var5[var7] >> 8 & 255);
  211.          var6[6 + var7 * 6 + 5] = (byte)(var5[var7] & 255);
  212.       }
  213.  
  214.       this.field_1.write(var6);
  215.    }
  216.  
  217.    void writeSetEncodings(int[] var1, int var2) throws IOException {
  218.       byte[] var3 = new byte[4 + 4 * var2];
  219.       var3[0] = 2;
  220.       var3[2] = (byte)(var2 >> 8 & 255);
  221.       var3[3] = (byte)(var2 & 255);
  222.  
  223.       for(int var4 = 0; var4 < var2; ++var4) {
  224.          var3[4 + 4 * var4] = (byte)(var1[var4] >> 24 & 255);
  225.          var3[5 + 4 * var4] = (byte)(var1[var4] >> 16 & 255);
  226.          var3[6 + 4 * var4] = (byte)(var1[var4] >> 8 & 255);
  227.          var3[7 + 4 * var4] = (byte)(var1[var4] & 255);
  228.       }
  229.  
  230.       this.field_1.write(var3);
  231.    }
  232.  
  233.    void writeClientCutText(String var1) throws IOException {
  234.       byte[] var2 = new byte[8 + var1.length()];
  235.       var2[0] = 6;
  236.       var2[4] = (byte)(var1.length() >> 24 & 255);
  237.       var2[5] = (byte)(var1.length() >> 16 & 255);
  238.       var2[6] = (byte)(var1.length() >> 8 & 255);
  239.       var2[7] = (byte)(var1.length() & 255);
  240.       byte[] var3 = var1.getBytes();
  241.       System.arraycopy(var3, 0, var2, 8, var1.length());
  242.       this.field_1.write(var2);
  243.    }
  244.  
  245.    void writePointerEvent(int var1, int var2, int var3) throws IOException {
  246.       byte[] var4 = new byte[6];
  247.       if (var3 == 0) {
  248.          this.pointerMask = 0;
  249.       }
  250.  
  251.       if (var3 == 1) {
  252.          this.pointerMask = 1;
  253.       }
  254.  
  255.       if (var3 == 2) {
  256.          this.pointerMask = 2;
  257.       }
  258.  
  259.       if (var3 == 3) {
  260.          this.pointerMask = 4;
  261.       }
  262.  
  263.       this.eventBufLen = 0;
  264.       if (var1 < 0) {
  265.          var1 = 0;
  266.       }
  267.  
  268.       if (var2 < 0) {
  269.          var2 = 0;
  270.       }
  271.  
  272.       this.eventBuf[this.eventBufLen++] = 5;
  273.       this.eventBuf[this.eventBufLen++] = (byte)this.pointerMask;
  274.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 8 & 255);
  275.       this.eventBuf[this.eventBufLen++] = (byte)(var1 & 255);
  276.       this.eventBuf[this.eventBufLen++] = (byte)(var2 >> 8 & 255);
  277.       this.eventBuf[this.eventBufLen++] = (byte)(var2 & 255);
  278.       this.field_1.write(this.eventBuf, 0, this.eventBufLen);
  279.    }
  280.  
  281.    void writeKeyEvent(int var1, boolean var2) throws IOException {
  282.       this.eventBufLen = 0;
  283.       this.eventBuf[this.eventBufLen++] = 4;
  284.       this.eventBuf[this.eventBufLen++] = (byte)(var2 ? 1 : 0);
  285.       this.eventBuf[this.eventBufLen++] = 0;
  286.       this.eventBuf[this.eventBufLen++] = 0;
  287.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 24 & 255);
  288.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 16 & 255);
  289.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 8 & 255);
  290.       this.eventBuf[this.eventBufLen++] = (byte)(var1 & 255);
  291.       this.field_1.write(this.eventBuf, 0, this.eventBufLen);
  292.    }
  293. }
  294.